/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>店铺分类管理</h3>
        <h5>网站系统店铺分类索引与管理</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>店铺分类管理, 由总平台设置管理.</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>店铺分类列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <div class="add" @click="toAdd()">
          <span>
            <i class="el-icon-circle-plus" /> 新增店铺分类
          </span>
        </div>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="分类名称" prop="sc_name" width="150"></el-table-column>
        <el-table-column label="保证金额度" prop="sc_bail" width="130"></el-table-column>
        <el-table-column label="排序" prop="sc_sort" width="130"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
			  <el-button-group>
				<el-button size="small" @click="toEdit(scope.row.sc_id)" icon="el-icon-edit-outline">编辑</el-button>
				<el-button size="small" @click="remove(scope.row.sc_id)" icon="el-icon-delete">删除</el-button>
			  </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {getStoreClassPage,updateStoreClass,deleteStoreClass} from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10
    };
  },
  components: {},
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
	  getStoreClassPage({
		  p: that.currentPage,
		  size: that.pageSize
	  })
	  .then(function(res) {
	    that.tableData = res.records;
	    that.totalCount = res.total;
	  });
    },
    refresh() {
      this.getPage();
      this.$message({
        type: "success",
        message: "刷新成功！"
      });
    },
    updateSort(row) {
      var storeClass = {
        sc_id: row.sc_id,
        sc_sort: row.sc_sort
      };
      var that = this;
	  updateStoreClass(storeClass).then(function(res) {
        if (res.status == 1) {
          that.getPage();
        }
      });
    },
    remove(scId) {
      var that = this;
      this.$confirm("是否删除该分类?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
		  deleteStoreClass(scId)
		  .then(function(res) {
		    if (res.status == 1) {
		      that.getPage();
		      that.$message({
		        type: "success",
		        message: "删除成功!"
		      });
		    } else {
		      that.$message.error({
		        message: res.msg
		      });
		    }
		  });
        })
        .catch(() => {
          that.$message.info({
            message: "已取消删除"
          });
        });
    },
    toAdd() {
      this.$router.push({
        name: "store_class_add",
        params: {
          currentPage: this.currentPage
        }
      });
    },
    toEdit(scId) {
      this.$router.push({
        name: "store_class_edit",
        params: {
          scId: scId,
          currentPage: this.currentPage
        }
      });
    }
  }
};
</script>

<style scoped>
</style>
